<template>
  <a-config-provider :locale="ant.locale">
    <router-view></router-view>
  </a-config-provider>
</template>
<script lang="ts">
  import {useStore} from "vuex";
  import {ConfigProvider} from 'ant-design-vue';
  import {getAntLocale} from "@/languages";
  import Emitter from "@/utils/emitter";
  import {useI18n} from "vue-i18n";
  import {onMounted, onBeforeMount, reactive} from 'vue';
  export default {
    components: {
      [ConfigProvider.name]: ConfigProvider
    },
    setup() {
      const store = useStore();
      const emitter = Emitter.shared().emitter;
      const ant = reactive({
        locale: getAntLocale(store.getters['setting/locale'])
      });
      const {locale} = useI18n();
      onMounted(()=>{
        emitter.on('change-language', (lang: string) => {
          ant.locale = getAntLocale(lang);
          locale.value = lang;
        })
      });
      onBeforeMount(()=>{
        emitter.all.clear();
      })
      return {
        ant
      }
    }
  }
</script>
<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  padding: 30px;
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
</style>
